package apoc.core.core.handler;

import apoc.core.entity.ApocPlayerProperties;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

public class PlayerHandler
{

    @SubscribeEvent
    public void onPlayerConstructed(EntityEvent.EntityConstructing event)
    {
        if (event.entity instanceof EntityPlayer && !event.entity.worldObj.isRemote)
        {
            EntityPlayer player = (EntityPlayer) event.entity;
            if (player.getExtendedProperties(ApocPlayerProperties.IDENTIFIER) == null)
                player.registerExtendedProperties(ApocPlayerProperties.IDENTIFIER, new ApocPlayerProperties());
        }
    }

    @SubscribeEvent
    public void onPlayerJoinWorld(EntityJoinWorldEvent event)
    {
        if (event.entity instanceof EntityPlayer && !event.entity.worldObj.isRemote)
            ApocPlayerProperties.getByEntity((EntityPlayer) event.entity).sync();
    }

}
